﻿



 

namespace Common.Algorithm.Core.LocalTest;

public class NSGAIIExecute
{

    static BinhKornFunction function = new BinhKornFunction();
    public static List<double[]> Run()
    {
        //GetFunctions();

        NSGAIIBinaryService service = new NSGAIIBinaryService(GetFunctions());
        service.decodeFunc = function.BinaryDecode; 
        Action action = () =>
        {
            service.RunAlgm(18);
        };
        Console.WriteLine($"time:{TimeService.TimeWatch(action)}");

        foreach (var sequence in NSGAIIBinaryService.sequences)
        {
            var doubles = function.BinaryDecode(sequence.genes);
            var v1 = function.GenMathFunction1().Invoke(doubles);
            var v2 = function.GenMathFunction2().Invoke(doubles);
            Console.WriteLine($"{doubles[0]},{doubles[1]}");
            Console.WriteLine($" {v1}, {v2}");
        }
        return NSGAIIBinaryService.records;
    }


    public static List<Func<int[], double>> GetFunctions()
    { 
        Func<int[], double> func11 = (ints) =>
        {
            var doubles = function.BinaryDecode(ints);
            var func1 = function.GenMathFunction1();
            return func1(doubles);
        };

        Func<int[], double> func22 = (ints) =>
        {
            var doubles = function.BinaryDecode(ints);
            var func2 = function.GenMathFunction2();
            return func2(doubles);
        };
        return new List<Func<int[], double>>() { func11, func22 };
    }



}
